<template>
  <div>
    <el-alert title="查询信息" type="info" :closable="false"></el-alert>
    <el-form inline :model="form">
      <el-form-item label="采集设备名称">
        <el-input
          v-model="form.sensorName"
          placeholder="请输入采集设备名称"
          size="medium"
        ></el-input>
      </el-form-item>
      <el-form-item label="采集主题">
        <el-select
          v-model="form.moduleEnum"
          size="medium"
          clearable
          placeholder="请选择采集主题"
        >
          <el-option label="北斗" value="00"></el-option>
          <el-option label="岩土" value="01"></el-option>
          <el-option label="气象" value="02"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="info" size="medium" @click="search(1)">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="info" size="medium" @click="addDevice = true"
          >新增</el-button
        >
      </el-form-item>
    </el-form>
    <el-alert title="采集设备信息列表" type="info" :closable="false"></el-alert>
    <el-table
      :data="tableData"
      stripe
      :cell-style="{ padding: '0' }"
      v-loading="loading"
    >
      <el-table-column
        label="设备名称"
        prop="sensorName"
        align="center"
      ></el-table-column>
      <el-table-column label="采集主题" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.moduleEnum == '00'">北斗监测</span>
          <span v-if="scope.row.moduleEnum == '01'">岩土监测</span>
          <span v-if="scope.row.moduleEnum == '02'">气象监测</span>
        </template>
      </el-table-column>
      <el-table-column
        label="监测体"
        prop="monitorName"
        align="center"
      ></el-table-column>
      <el-table-column label="设备生产商" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.productEnum == '00'">天宝</span>
          <span v-if="scope.row.productEnum == '01'">司南</span>
          <span v-if="scope.row.productEnum == '02'">基康</span>
          <span v-if="scope.row.productEnum == '03'">阳光</span>
          <span v-if="scope.row.productEnum == '05'">易周</span>
        </template>
      </el-table-column>
      <el-table-column
        label="设备IP"
        prop="monitorIp"
        align="center"
      ></el-table-column>
      <el-table-column label="采集协议" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.monitorProtocol == '00'">TCP</span>
          <span v-if="scope.row.monitorProtocol == '01'">NTRIP</span>
        </template>
      </el-table-column>
      <el-table-column
        label="服务端口"
        prop="monitorPort"
        align="center"
      ></el-table-column>
      <el-table-column
        label="基准站"
        prop="baseName"
        align="center"
      ></el-table-column>
      <el-table-column
        label="登录名"
        prop="loginName"
        align="center"
      ></el-table-column>
      <el-table-column
        label="密码"
        prop="password"
        align="center"
      ></el-table-column>
      <el-table-column
        label="采集频率"
        prop="reportIntervalTime"
        align="center"
      ></el-table-column>
      <el-table-column
        label="经度"
        prop="xoriginal"
        align="center"
      ></el-table-column>
      <el-table-column
        label="纬度"
        prop="yoriginal"
        align="center"
      ></el-table-column>
      <el-table-column label="是否鉴权" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.whetherAuthentication == '01'">是</span>
          <span v-if="scope.row.whetherAuthentication == '02'">否</span>
        </template>
      </el-table-column>
      <el-table-column
        label="创建时间"
        prop="createTime"
        align="center"
      ></el-table-column>
      <el-table-column label="站点状态" align="center"></el-table-column>
      <el-table-column label="操作" align="center" width="145">
        <template slot-scope="scope">
          <div>
            <el-link
              type="primary"
              :underline="false"
              @click="editInfo(scope.row)"
              >修改</el-link
            >&nbsp;
            <el-link type="primary" :underline="false" @click="del(scope.row)"
              >删除</el-link
            >
          </div>
        </template>
      </el-table-column>
    </el-table>
    <el-row type="flex" justify="end">
      <el-col :span="10">
        <el-pagination
          background
          :current-page="pageData.currentPage"
          layout="total, prev, pager, next, jumper"
          :total="pageData.count"
          :page-size="pageData.pageSize"
          @current-change="handleCurrentChange"
          v-if="pageData.count && pageData.count != 0"
        >
        </el-pagination>
      </el-col>
    </el-row>
    <!-- 新增采集设备 -->
    <el-dialog
      title="增加采集设备"
      :visible.sync="addDevice"
      :before-close="closeDialog"
      width="40%"
    >
      <el-form
        :model="addForm"
        ref="addForm"
        :rules="rules"
        label-position="left"
        label-width="100px"
        inline
      >
        <el-form-item prop="moduleEnum" label="采集主题">
          <el-select
            placeholder="请选择采集主题"
            v-model="addForm.moduleEnum"
            @change="cjztChange"
          >
            <el-option label="北斗" value="00"></el-option>
            <el-option label="岩土" value="01"></el-option>
            <el-option label="气象" value="02"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="sensorName" label="站点名称">
          <el-input
            placeholder="请输入站点名称"
            v-model="addForm.sensorName"
          ></el-input>
        </el-form-item>
        <el-form-item
          prop="sensorNumber1"
          label="区站号"
          v-if="this.addForm.productEnum == '03'"
        >
          <el-input
            placeholder="请输入6位区站号"
            v-model="addForm.sensorNumber1"
          ></el-input>
        </el-form-item>
        <el-form-item
          prop="sensorNumber4"
          label="区站号"
          v-if="this.addForm.productEnum == '05'"
        >
          <el-input
            placeholder="请输入2位区站号"
            v-model="addForm.sensorNumber4"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="设备标识号"
          prop="sensorNumber2"
          v-if="this.addForm.productEnum == '03'"
        >
          <el-input
            placeholder="请输入4位设备标识号"
            v-model="addForm.sensorNumber2"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="设备ID"
          prop="sensorNumber3"
          v-if="this.addForm.productEnum == '03'"
        >
          <el-input
            placeholder="请输入3位设备ID"
            v-model="addForm.sensorNumber3"
          ></el-input>
        </el-form-item>
        <el-form-item prop="productEnum" label="设备生产商">
          <el-select
            placeholder="请选择生产商"
            v-model="addForm.productEnum"
            @change="sbscsChange"
          >
            <el-option
              label="天宝"
              value="00"
              v-if="
                this.addForm.moduleEnum == '00' || this.addForm.moduleEnum == ''
              "
            ></el-option>
            <el-option
              label="司南"
              value="01"
              v-if="
                this.addForm.moduleEnum == '00' || this.addForm.moduleEnum == ''
              "
            ></el-option>
            <el-option
              label="基康"
              value="02"
              v-if="
                this.addForm.moduleEnum == '01' || this.addForm.moduleEnum == ''
              "
            ></el-option>
            <el-option
              label="阳光"
              value="03"
              v-if="
                this.addForm.moduleEnum == '02' || this.addForm.moduleEnum == ''
              "
            ></el-option>
            <el-option
              label="易周"
              value="05"
              v-if="
                this.addForm.moduleEnum == '02' || this.addForm.moduleEnum == ''
              "
            ></el-option>
            <el-option
              label="隼星"
              value="06"
              v-if="this.addForm.moduleEnum == ''"
            ></el-option>
            <el-option
              label="YK"
              value="07"
              v-if="this.addForm.moduleEnum == ''"
            ></el-option>
            <el-option
              label="宥思"
              value="08"
              v-if="this.addForm.moduleEnum == ''"
            ></el-option>
            <el-option
              label="莫尼特"
              value="09"
              v-if="this.addForm.moduleEnum == ''"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="采集频率"
          prop="reportIntervalTime"
          v-if="
            this.addForm.moduleEnum == '01' || this.addForm.productEnum == '05'
          "
        >
          <el-input
            placeholder="请输入采集频率单位：分钟"
            v-model="addForm.reportIntervalTime"
          ></el-input>
        </el-form-item>
        <el-form-item
          prop="monitorPort"
          label="服务端口"
          v-if="this.addForm.moduleEnum == '00'"
        >
          <el-input
            placeholder="请输入服务端口号"
            v-model="addForm.monitorPort"
          ></el-input>
        </el-form-item>
        <el-form-item label="监测体" prop="monitorId">
          <el-select placeholder="请选择监测体" v-model="addForm.monitorId">
            <el-option
              v-for="item in monitorList"
              :key="item.key"
              :label="item.value"
              :value="item.key"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="数据类型"
          prop="dataType"
          v-if="this.addForm.moduleEnum == '01'"
        >
          <el-select placeholder="请选择数据类型" v-model="addForm.dataType">
            <el-option label="测斜" value="01"></el-option>
            <el-option label="裂缝" value="02"></el-option>
            <el-option label="渗压(地下水位)" value="0301"></el-option>
            <el-option label="渗压(孔隙水压力)" value="0302"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="参数G"
          v-if="
            this.addForm.dataType == '01' ||
            this.addForm.dataType == '02' ||
            this.addForm.dataType == '0301' ||
            this.addForm.dataType == '0302'
          "
        >
          <el-input
            placeholder="请输入参数G"
            v-model="addForm.argumentG"
          ></el-input>
        </el-form-item>
        <el-form-item label="仪器长度" v-if="this.addForm.dataType == '01'">
          <el-input
            placeholder="请输入仪器长度"
            v-model="addForm.argumentL"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="温补系数K"
          v-if="
            this.addForm.dataType == '02' ||
            this.addForm.dataType == '0301' ||
            this.addForm.dataType == '0302'
          "
        >
          <el-input
            placeholder="请输入温补系数K"
            v-model="addForm.argumentK"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="温补初值"
          v-if="
            this.addForm.dataType == '02' ||
            this.addForm.dataType == '0301' ||
            this.addForm.dataType == '0302'
          "
        >
          <el-input
            placeholder="请输入温补初值"
            v-model="addForm.argumentT"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="初始读数值"
          v-if="
            this.addForm.dataType == '01' ||
            this.addForm.dataType == '02' ||
            this.addForm.dataType == '0301' ||
            this.addForm.dataType == '0302'
          "
        >
          <el-input
            placeholder="请输入初始读数值"
            v-model="addForm.argumentR"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="初始绳长值"
          v-if="
            this.addForm.dataType == '01' || this.addForm.dataType == '0301'
          "
        >
          <el-input
            placeholder="请输入初始绳长值"
            v-model="addForm.nozzleHeight"
          ></el-input>
        </el-form-item>
        <el-form-item label="深部位移序号" v-if="this.addForm.dataType == '01'">
          <el-input
            placeholder="请输入深部位移序号"
            v-model="addForm.sensorSerialNumber"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="基准站"
          prop="baseId"
          v-if="this.addForm.moduleEnum == '00'"
        >
          <el-select placeholder="请选择基准站" v-model="addForm.baseId">
            <el-option
              v-for="item in baseList"
              :key="item.key"
              :label="item.value"
              :value="item.key"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="采集协议" prop="monitorProtocol">
          <el-select
            placeholder="请选择采集协议"
            v-model="addForm.monitorProtocol"
            :disabled="isCJDisabled"
            @change="cjxyChange"
          >
            <el-option label="TCP" value="00"></el-option>
            <el-option label="NTRIP" value="01"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="是否鉴权"
          v-if="
            this.addForm.monitorProtocol == '00' ||
            this.addForm.monitorProtocol == '01' ||
            this.addForm.moduleEnum == '02' ||
            this.addForm.moduleEnum == '01'
          "
          prop="whetherAuthentication"
        >
          <el-select
            placeholder="请选择"
            v-model="addForm.whetherAuthentication"
            :disabled="isDisabled"
          >
            <el-option label="是" value="01"></el-option>
            <el-option label="否" value="02"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="登录名"
          prop="loginName"
          v-if="
            this.addForm.whetherAuthentication == '01' ||
            this.addForm.moduleEnum == '02' ||
            this.addForm.moduleEnum == '01'
          "
        >
          <el-input
            placeholder="请输入登录名"
            v-model="addForm.loginName"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="密码"
          prop="password"
          v-if="
            this.addForm.whetherAuthentication == '01' ||
            this.addForm.moduleEnum == '02' ||
            this.addForm.moduleEnum == '01'
          "
        >
          <el-input
            placeholder="请输入密码"
            v-model="addForm.password"
          ></el-input>
        </el-form-item>
        <!-- <el-form-item label="设备编号" v-if="issbbh">
          <el-input
            placeholder="请输入设备编号"
            v-model="addForm.sensorModel"
          ></el-input>
        </el-form-item> -->
        <el-form-item
          label="设备IP"
          prop="monitorIp"
          v-if="
            this.addForm.whetherAuthentication == '01' ||
            this.addForm.moduleEnum == '02' ||
            this.addForm.productEnum == '03' ||
            this.addForm.moduleEnum == '01'
          "
        >
          <el-input
            placeholder="请输入设备IP"
            v-model="addForm.monitorIp"
          ></el-input>
        </el-form-item>
        <!-- <el-form-item label="经度初始值" v-if="isjdcsz">
          <el-input
            placeholder="请输入X初始值"
            v-model="addForm.xOriginal"
          ></el-input>
        </el-form-item>
        <el-form-item label="纬度初始值" v-if="iswdcsz">
          <el-input
            placeholder="请输入Y初始值"
            v-model="addForm.yOriginal"
          ></el-input>
        </el-form-item> -->
        <el-form-item class="buttonfrom">
          <el-button type="primary" @click="add()">确定</el-button>
          <el-button @click="addDevice = false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!-- 修改采集设备 -->
    <el-dialog
      title="修改采集设备"
      :visible.sync="editDevice"
      :before-close="closeEditDialog"
      width="40%"
    >
      <el-form
        :model="editForm"
        ref="editForm"
        :rules="rules"
        label-position="left"
        label-width="100px"
        inline
      >
        <el-form-item prop="moduleEnum" label="采集主题">
          <el-select
            placeholder="请选择采集主题"
            :disabled="editDisabled"
            v-model="editForm.moduleEnum"
            @change="cjztChange"
          >
            <el-option label="北斗" value="00"></el-option>
            <el-option label="岩土" value="01"></el-option>
            <el-option label="气象" value="02"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="sensorName" label="站点名称">
          <el-input
            placeholder="请输入站点名称"
            v-model="editForm.sensorName"
          ></el-input>
        </el-form-item>
        <el-form-item
          prop="sensorNumber1"
          label="区站号"
          v-if="this.editForm.productEnum == '03'"
        >
          <el-input
            placeholder="请输入6位区站号"
            v-model="editForm.sensorNumber1"
          ></el-input>
        </el-form-item>
        <el-form-item
          prop="sensorNumber4"
          label="区站号"
          v-if="this.editForm.productEnum == '05'"
        >
          <el-input
            placeholder="请输入2位区站号"
            v-model="editForm.sensorNumber4"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="设备标识号"
          prop="sensorNumber2"
          v-if="this.editForm.productEnum == '03'"
        >
          <el-input
            placeholder="请输入4位设备标识号"
            v-model="editForm.sensorNumber2"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="设备ID"
          prop="sensorNumber3"
          v-if="this.editForm.productEnum == '03'"
        >
          <el-input
            placeholder="请输入3位设备ID"
            v-model="editForm.sensorNumber3"
          ></el-input>
        </el-form-item>
        <el-form-item prop="productEnum" label="设备生产商">
          <el-select
            placeholder="请选择生产商"
            v-model="editForm.productEnum"
            @change="sbscsChange"
          >
            <el-option
              label="天宝"
              value="00"
              v-if="
                this.editForm.moduleEnum == '00' ||
                this.editForm.moduleEnum == ''
              "
            ></el-option>
            <el-option
              label="司南"
              value="01"
              v-if="
                this.editForm.moduleEnum == '00' ||
                this.editForm.moduleEnum == ''
              "
            ></el-option>
            <el-option
              label="基康"
              value="02"
              v-if="
                this.editForm.moduleEnum == '01' ||
                this.editForm.moduleEnum == ''
              "
            ></el-option>
            <el-option
              label="阳光"
              value="03"
              v-if="
                this.editForm.moduleEnum == '02' ||
                this.editForm.moduleEnum == ''
              "
            ></el-option>
            <el-option
              label="易周"
              value="05"
              v-if="
                this.editForm.moduleEnum == '02' ||
                this.editForm.moduleEnum == ''
              "
            ></el-option>
            <el-option
              label="隼星"
              value="06"
              v-if="
                this.editForm.moduleEnum == '01' ||
                this.editForm.moduleEnum == ''
              "
            ></el-option>
            <el-option
              label="YK"
              value="07"
              v-if="
                this.editForm.moduleEnum == '01' ||
                this.editForm.moduleEnum == ''
              "
            ></el-option>
            <el-option
              label="宥思"
              value="08"
              v-if="
                this.editForm.moduleEnum == '01' ||
                this.editForm.moduleEnum == ''
              "
            ></el-option>
            <el-option
              label="莫尼特"
              value="09"
              v-if="this.editForm.moduleEnum == ''"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="采集频率"
          prop="reportIntervalTime"
          v-if="
            this.editForm.moduleEnum == '01' ||
            this.editForm.productEnum == '05'
          "
        >
          <el-input
            placeholder="请输入采集频率单位：分钟"
            v-model="editForm.reportIntervalTime"
          ></el-input>
        </el-form-item>
        <el-form-item
          prop="monitorPort"
          label="服务端口"
          v-if="this.editForm.moduleEnum == '00'"
        >
          <el-input
            placeholder="请输入服务端口号"
            v-model="editForm.monitorPort"
          ></el-input>
        </el-form-item>
        <el-form-item label="监测体" prop="monitorId">
          <el-select placeholder="请选择监测体" v-model="editForm.monitorId">
            <el-option
              v-for="item in monitorList"
              :key="item.key"
              :label="item.value"
              :value="item.key"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="数据类型"
          prop="dataType"
          v-if="this.editForm.moduleEnum == '01'"
        >
          <el-select placeholder="请选择数据类型" v-model="editForm.dataType">
            <el-option label="测斜" value="01"></el-option>
            <el-option label="裂缝" value="02"></el-option>
            <el-option label="渗压(地下水位)" value="0301"></el-option>
            <el-option label="渗压(孔隙水压力)" value="0302"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="参数G"
          v-if="
            this.editForm.dataType == '01' ||
            this.editForm.dataType == '02' ||
            this.editForm.dataType == '0301' ||
            this.editForm.dataType == '0302'
          "
        >
          <el-input
            placeholder="请输入参数G"
            v-model="editForm.argumentG"
          ></el-input>
        </el-form-item>
        <el-form-item label="仪器长度" v-if="this.editForm.dataType == '01'">
          <el-input
            placeholder="请输入仪器长度"
            v-model="editForm.argumentL"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="温补系数K"
          v-if="
            this.editForm.dataType == '02' ||
            this.editForm.dataType == '0301' ||
            this.editForm.dataType == '0302'
          "
        >
          <el-input
            placeholder="请输入温补系数K"
            v-model="editForm.argumentK"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="温补初值"
          v-if="
            this.editForm.dataType == '02' ||
            this.editForm.dataType == '0301' ||
            this.editForm.dataType == '0302'
          "
        >
          <el-input
            placeholder="请输入温补初值"
            v-model="editForm.argumentT"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="初始读数值"
          v-if="
            this.editForm.dataType == '01' ||
            this.editForm.dataType == '02' ||
            this.editForm.dataType == '0301' ||
            this.editForm.dataType == '0302'
          "
        >
          <el-input
            placeholder="请输入初始读数值"
            v-model="editForm.argumentR"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="初始绳长值"
          v-if="
            this.editForm.dataType == '01' || this.editForm.dataType == '0301'
          "
        >
          <el-input
            placeholder="请输入初始绳长值"
            v-model="editForm.nozzleHeight"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="深部位移序号"
          v-if="this.editForm.dataType == '01'"
        >
          <el-input
            placeholder="请输入深部位移序号"
            v-model="editForm.sensorSerialNumber"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="基准站"
          prop="baseId"
          v-if="this.editForm.moduleEnum == '00'"
        >
          <el-select placeholder="请选择基准站" v-model="editForm.baseId">
            <el-option
              v-for="item in baseList"
              :key="item.key"
              :label="item.value"
              :value="item.key"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="采集协议" prop="monitorProtocol">
          <el-select
            placeholder="请选择采集协议"
            v-model="editForm.monitorProtocol"
            :disabled="isCJDisabled"
            @change="cjxyChange"
          >
            <el-option label="TCP" value="00"></el-option>
            <el-option label="NTRIP" value="01"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="是否鉴权"
          v-if="
            this.editForm.monitorProtocol == '00' ||
            this.editForm.monitorProtocol == '01' ||
            this.editForm.moduleEnum == '02' ||
            this.editForm.moduleEnum == '01'
          "
          prop="whetherAuthentication"
        >
          <el-select
            placeholder="请选择"
            v-model="editForm.whetherAuthentication"
            :disabled="isDisabled"
          >
            <el-option label="是" value="01"></el-option>
            <el-option label="否" value="02"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="登录名"
          prop="loginName"
          v-if="
            this.editForm.whetherAuthentication == '01' &&
            (this.editForm.moduleEnum == '02' ||
              this.editForm.moduleEnum == '01' ||
              this.editForm.moduleEnum == '00')
          "
        >
          <el-input
            placeholder="请输入登录名"
            v-model="editForm.loginName"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="密码"
          prop="password"
          v-if="
            (this.editForm.moduleEnum == '02' ||
              this.editForm.moduleEnum == '01' ||
              this.editForm.moduleEnum == '00') &&
            this.editForm.whetherAuthentication == '01'
          "
        >
          <el-input
            placeholder="请输入密码"
            v-model="editForm.password"
          ></el-input>
        </el-form-item>
        <!-- <el-form-item label="设备编号" v-if="issbbh">
          <el-input
            placeholder="请输入设备编号"
            v-model="editForm.sensorModel"
          ></el-input>
        </el-form-item> -->
        <el-form-item
          label="设备IP"
          prop="monitorIp"
          v-if="
            this.editForm.whetherAuthentication == '01' ||
            this.editForm.moduleEnum == '02' ||
            this.editForm.productEnum == '03' ||
            this.editForm.moduleEnum == '01'
          "
        >
          <el-input
            placeholder="请输入设备IP"
            v-model="editForm.monitorIp"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="经度初始值"
          v-if="this.editForm.moduleEnum == '00'"
        >
          <el-input
            placeholder="请输入X初始值"
            v-model="editForm.xOriginal"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="纬度初始值"
          v-if="this.editForm.moduleEnum == '00'"
        >
          <el-input
            placeholder="请输入Y初始值"
            v-model="editForm.yOriginal"
          ></el-input>
        </el-form-item>
        <el-form-item class="buttonfrom">
          <el-button type="primary" @click="isEdit()">确定</el-button>
          <el-button @click="editDevice = false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import Axios from "axios";
import moment from "moment";
import * as serviceApi from "../../common/service.config";
Axios.defaults.withcredentials = true;

export default {
  name: "DeviceCollection",
  data() {
    return {
      form: {
        sensorName: "",
        moduleEnum: "",
      },
      tableData: null,
      pageData: {
        currentPage: null,
        count: null,
        pageSize: null,
      },
      loading: null,
      addDevice: false,
      addForm: {
        moduleEnum: "", //采集主题
        sensorName: "", //站点名称
        sensorNumber1: "", //区站号6
        sensorNumber2: "", //设备标识号
        sensorNumber3: "", //设备ID
        sensorNumber4: "", //区站号2
        productEnum: "", //设备生产商
        monitorPort: "", //服务端口
        reportIntervalTime: "", //采集频率
        sensorModel: "",
        xOriginal: "",
        yOriginal: "",
        monitorIp: "", //设备IP
        dataType: "", //数据类型
        loginName: "", //登录名
        password: "", //密码
        monitorId: "", //监测体
        baseId: "", //基准站
        monitorProtocol: "", //采集协议
        whetherAuthentication: "", //鉴权
        argumentG: "", // 参数G
        argumentL: "", // 仪器长度
        argumentK: "", // 温补系数K
        argumentT: "", // 温补初值
        argumentR: "", // 初始读数值
        nozzleHeight: "", // 初始绳长值
        sensorSerialNumber: "", // 深部位移序号
      },
      editDisabled: true,
      editDevice: false,
      editForm: {
        sensorId: "",
        moduleEnum: "", //采集主题
        sensorName: "", //站点名称
        sensorNumber1: "", //区站号6
        sensorNumber2: "", //设备标识号
        sensorNumber3: "", //设备ID
        sensorNumber4: "", //区站号2
        productEnum: "", //设备生产商
        monitorPort: "", //服务端口
        reportIntervalTime: "", //采集频率
        sensorModel: "",
        xOriginal: "",
        yOriginal: "",
        monitorIp: "", //设备IP
        dataType: "", //数据类型
        loginName: "", //登录名
        password: "", //密码
        monitorId: "", //监测体
        baseId: "", //基准站
        monitorProtocol: "", //采集协议
        whetherAuthentication: "", //鉴权
        argumentG: "", // 参数G
        argumentL: "", // 仪器长度
        argumentK: "", // 温补系数K
        argumentT: "", // 温补初值
        argumentR: "", // 初始读数值
        nozzleHeight: "", // 初始绳长值
        sensorSerialNumber: "", // 深部位移序号
      },
      rules: {
        moduleEnum: [
          { required: true, message: "请选择采集主题", trigger: "change" },
        ],
        sensorName: [
          { required: true, message: "请输入站点名称", trigger: "blur" },
        ],
        monitorId: [
          { required: true, message: "请选择监测体", trigger: "change" },
        ],
        monitorProtocol: [
          { required: true, message: "请选择采集协议", trigger: "change" },
        ],
        whetherAuthentication: [
          { message: "请选择是否鉴权", trigger: "change" },
        ],

        productEnum: [{ message: "请选择生产商", trigger: "change" }],
        monitorPort: [
          {
            pattern: /^([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5])$/,
            message: "端口号：0-65535",
            trigger: "blur",
          },
          {
            message: "请输入服务端口号",
            trigger: "blur",
          },
        ],
        loginName: [{ message: "请输入登录名", trigger: "blur" }],
        password: [
          {
            pattern: /^\w{6,20}$/,
            message: "密码必须是(6-20)位字母、数字和下划线组合(不含空格)",
            trigger: "blur",
          },
        ],
        monitorIp: [
          {
            pattern:
              /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}$/,
            message: "格式：255.255.255.1",
            trigger: "blur",
          },
        ],
        baseId: [{ message: "请选择基准站", trigger: "change" }],
        sensorNumber1: [
          {
            pattern: /^[a-zA-Z0-9]{6}$/,
            message: "格式：6位英文，数字，及其组合",
            trigger: "blur",
          },
        ],
        sensorNumber4: [
          {
            pattern: /^[a-zA-Z0-9]{2}$/,
            message: "格式：2位英文，数字，及其组合",
            trigger: "blur",
          },
        ],
        sensorNumber2: [
          {
            pattern: /^[a-zA-Z0-9]{4}$/,
            message: "格式：4位英文，数字，及其组合",
            trigger: "blur",
          },
        ],
        sensorNumber3: [
          {
            pattern: /^[a-zA-Z0-9]{3}$/,
            message: "格式：3位英文，数字，及其组合",
            trigger: "blur",
          },
        ],
        // reportIntervalTime: [
        //   {
        //     message: "请输入采集频率单位：分钟",
        //     trigger: "blur",
        //   },
        // ],
        dataType: [{ message: "请输入选择", trigger: "change" }],
      },
      baseList: [],
      monitorList: [],
      isCJDisabled: false, //选择框禁用
      isDisabled: false, //选择框禁用
    };
  },
  created() {
    let queryData = {
      currentPage: "1",
      sensorName: "",
      moduleEnum: "",
    };
    this.deviceCollection(queryData);
    this.getMonitorList();
    this.getBaseList();
  },
  methods: {
    deviceCollection(queryData) {
      // this.loading = true;
      Axios({
        url: serviceApi.KB_API,
        method: "post",
        data: `appMsg={"parameter":"{\\"page\\":{\\"currentPage\\":${queryData.currentPage},\\"pageSize\\":10},\\"sensorName\\":\\"${queryData.sensorName}\\",\\"moduleEnum\\":\\"${queryData.moduleEnum}\\"}","serviceCode":"listSensorInfoByPage","timestamp":"","uuid":""}`,
      }).then((res) => {
        this.loading = false;
        this.pageData = res.data.parameter.page;
        let list = res.data.parameter.list;
        for (let i = 0; i < list.length; i++) {
          list[i].checkWarning = list[i].checkWarning / 3600000 + 8;
          list[i].createTime = moment(list[i].createTime).format(
            "YYYY-MM-DD HH:mm:ss"
          );
        }
        this.tableData = list;
      });
    },
    search(currentPage) {
      let queryData = {
        currentPage: currentPage,
        sensorName: this.form.sensorName,
        moduleEnum: this.form.moduleEnum,
      };
      this.deviceCollection(queryData);
    },
    handleCurrentChange(val) {
      this.search(val);
    },
    // 监测体列表
    getMonitorList() {
      Axios({
        url: serviceApi.KB_API,
        method: "post",
        data: `appMsg={"parameter":"{\\"type\\":\\"2\\"}","serviceCode":"querySelect","timestamp":"","uuid":""}`,
      }).then((res) => {
        console.log(res);
        this.monitorList = res.data.parameter.list;
      });
    },
    // 基准站列表
    getBaseList() {
      Axios({
        url: serviceApi.KB_API,
        method: "post",
        data: `appMsg={"parameter":"{\\"type\\":\\"7\\"}","serviceCode":"querySelect","timestamp":"","uuid":""}`,
      }).then((res) => {
        this.baseList = res.data.parameter.list;
      });
    },
    // 采集主题
    cjztChange(selectValue) {
      if (selectValue == "00") {
        this.isCJDisabled = false;
        this.isDisabled = false;
      } else if (selectValue == "01") {
        this.isCJDisabled = true;
        this.isDisabled = true;
        this.addForm.whetherAuthentication = "01";
        this.addForm.monitorProtocol = "00";
      } else if (selectValue == "02") {
        this.addForm.monitorProtocol = "00";
        this.addForm.whetherAuthentication = "01";
        this.isCJDisabled = true;
        this.isDisabled = true;
      }
    },
    // 设备生产商
    sbscsChange(selectValue) {
      if (selectValue == "03") {
        this.isCJDisabled = true;
        this.isDisabled = true;
        this.addForm.monitorProtocol = "00";
        this.addForm.whetherAuthentication = "01";
      } else if (selectValue == "05") {
        this.isCJDisabled = true;
        this.isDisabled = true;
        this.addForm.monitorProtocol = "00";
        this.addForm.whetherAuthentication = "01";
      }
    },
    // 采集协议
    cjxyChange(selectValue) {
      if (selectValue == "00") {
        this.isDisabled = false;
        this.isCJDisabled = false;
        this.addForm.whetherAuthentication = "";
      } else if (selectValue == "01") {
        this.addForm.whetherAuthentication = "01";
        this.editForm.whetherAuthentication = "01";
        this.isCJDisabled = false;
        this.isDisabled = true;
      }
    },
    add() {
      this.$refs["addForm"].validate((valid) => {
        if (valid) {
          const formData = new FormData();
          for (const [key, value] of Object.entries(this.addForm)) {
            formData.append(key, value);
          }
          Axios({
            url: serviceApi.KB_API,
            method: "post",
            data: `appMsg={"parameter":"{\\"moduleEnum\\":\\"${this.addForm.moduleEnum}\\",\\"sensorName\\":\\"${this.addForm.sensorName}\\",\\"sensorNumber1\\":\\"${this.addForm.sensorNumber1}\\",\\"sensorNumber4\\":\\"${this.addForm.sensorNumber4}\\",\\"sensorNumber2\\":\\"${this.addForm.sensorNumber2}\\",\\"sensorNumber3\\":\\"${this.addForm.sensorNumber3}\\",\\"productEnum\\":\\"${this.addForm.productEnum}\\",\\"monitorPort\\":\\"${this.addForm.monitorPort}\\",\\"reportIntervalTime\\":\\"${this.addForm.reportIntervalTime}\\",\\"sensorModel\\":\\"${this.addForm.sensorModel}\\",\\"xOriginal\\":\\"${this.addForm.xOriginal}\\",\\"yOriginal\\":\\"${this.addForm.yOriginal}\\",\\"monitorIp\\":\\"${this.addForm.monitorIp}\\",\\"dataType\\":\\"${this.addForm.dataType}\\",\\"loginName\\":\\"${this.addForm.loginName}\\",\\"password\\":\\"${this.addForm.password}\\",\\"monitorId\\":\\"${this.addForm.monitorId}\\",\\"baseId\\":\\"${this.addForm.baseId}\\",\\"monitorProtocol\\":\\"${this.addForm.monitorProtocol}\\",\\"whetherAuthentication\\":\\"${this.addForm.whetherAuthentication}\\",\\"argumentG\\":\\"${this.addForm.argumentG}\\",\\"argumentL\\":\\"${this.addForm.argumentL}\\",\\"argumentK\\":\\"${this.addForm.argumentK}\\",\\"argumentT\\":\\"${this.addForm.argumentT}\\",\\"argumentR\\":\\"${this.addForm.argumentR}\\",\\"nozzleHeight\\":\\"${this.addForm.nozzleHeight}\\",\\"sensorSerialNumber\\":\\"${this.addForm.sensorSerialNumber}\\"}","serviceCode":"addSensorInfo","timestamp":"","uuid":""}`,
          }).then((res) => {
            if (res.data.parameter.status == "0000") {
              this.$message({
                message: "新增成功",
                type: "success",
                duration: 1000,
                onClose: () => {
                  let queryData = {
                    currentPage: "1",
                    sensorName: "",
                    moduleEnum: "",
                  };
                  this.deviceCollection(queryData);
                },
              });
              this.$refs.addForm.resetFields();
            } else {
              this.$message({
                message: res.data.message,
                type: "warning",
              });
            }
          });
        } else {
          this.$message({
            type: "error",
            message: "请完善表单信息",
            offset: 400,
            duration: 1000,
          });
        }
        this.addDevice = false;
      });
    },
    closeDialog() {
      this.addDevice = false;
      this.$refs.addForm.resetFields();
    },
    editInfo(row) {
      this.editDevice = true;
      this.editForm.sensorId = row.id;
      this.editForm.moduleEnum = row.moduleEnum;
      this.editForm.sensorName = row.sensorName;
      this.editForm.productEnum = row.productEnum;
      this.editForm.monitorId = String(row.monitorId);
      if (row.monitorPort) {
        this.editForm.monitorPort = row.monitorPort;
      } else {
        this.editForm.monitorPort = "";
      }
      if (row.sensorNumber1) {
        this.editForm.sensorNumber1 = row.sensorNumber1;
      } else {
        this.editForm.sensorNumber1 = "";
      }
      if (row.sensorNumber2) {
        this.editForm.sensorNumber2 = row.sensorNumber2;
      } else {
        this.editForm.sensorNumber2 = "";
      }
      if (row.sensorNumber3) {
        this.editForm.sensorNumber3 = row.sensorNumber3;
      } else {
        this.editForm.sensorNumber3 = "";
      }
      if (row.sensorNumber4) {
        this.editForm.sensorNumber4 = row.sensorNumber4;
      } else {
        this.editForm.sensorNumber4 = "";
      }
      if (row.reportIntervalTime) {
        this.editForm.reportIntervalTime = row.reportIntervalTime;
      } else {
        this.editForm.reportIntervalTime = "";
      }
      if (row.xOriginal) {
        this.editForm.xOriginal = row.xOriginal;
      } else {
        this.editForm.xOriginal = "";
      }
      if (row.yOriginal) {
        this.editForm.yOriginal = row.yOriginal;
      } else {
        this.editForm.yOriginal = "";
      }
      if (row.monitorIp) {
        this.editForm.monitorIp = row.monitorIp;
      } else {
        this.editForm.monitorIp = "";
      }
      if (row.dataType) {
        this.editForm.dataType = row.dataType;
      } else {
        this.editForm.dataType = "";
      }
      if (row.loginName) {
        this.editForm.loginName = row.loginName;
      } else {
        this.editForm.loginName = "";
      }
      if (row.password) {
        this.editForm.password = row.password;
      } else {
        this.editForm.password = "";
      }
      if (row.whetherAuthentication) {
        this.editForm.whetherAuthentication = row.whetherAuthentication;
      } else {
        this.editForm.whetherAuthentication = "";
      }
      if (row.monitorProtocol) {
        this.editForm.monitorProtocol = row.monitorProtocol;
      } else {
        this.editForm.monitorProtocol = "";
      }
      if (row.baseId) {
        this.editForm.baseId = String(row.baseId);
      } else {
        this.editForm.baseId = "";
      }
      if (row.argumentG) {
        this.editForm.argumentG = row.argumentG;
      } else {
        this.editForm.argumentG = "";
      }
      if (row.argumentL) {
        this.editForm.argumentL = row.argumentL;
      } else {
        this.editForm.argumentL = "";
      }
      if (row.argumentK) {
        this.editForm.argumentK = row.argumentK;
      } else {
        this.editForm.argumentK = "";
      }
      if (row.argumentT) {
        this.editForm.argumentT = row.argumentT;
      } else {
        this.editForm.argumentT = "";
      }
      if (row.argumentR) {
        this.editForm.argumentR = row.argumentR;
      } else {
        this.editForm.argumentR = "";
      }
      if (row.sensorSerialNumber) {
        this.editForm.sensorSerialNumber = row.sensorSerialNumber;
      } else {
        this.editForm.argumentR = "";
      }
      if (row.nozzleHeight) {
        this.editForm.nozzleHeight = row.nozzleHeight;
      } else {
        this.editForm.nozzleHeight = "";
      }
      // this.editForm.reportIntervalTime = row.reportIntervalTime;
      // this.editForm.sensorNumber2 = row.sensorNumber2;
      // this.editForm.sensorNumber3 = row.sensorNumber3;
      // this.editForm.sensorNumber4 = row.sensorNumber4;
      // this.editForm.reportIntervalTime = row.reportIntervalTime;
      // this.editForm.dataType = row.dataType;
      // this.editForm.argumentG = row.argumentG;
      // this.editForm.argumentL = row.argumentL;
      // this.editForm.argumentK = row.argumentK;
      // this.editForm.argumentT = row.argumentT;
      // this.editForm.argumentR = row.argumentR;
      // this.editForm.nozzleHeight = row.nozzleHeight;
      // this.editForm.sensorSerialNumber = row.sensorSerialNumber;
      // this.editForm.baseId = String(row.baseId);
      // this.editForm.monitorProtocol = row.monitorProtocol;
      // this.editForm.whetherAuthentication = row.whetherAuthentication;
      // this.editForm.loginName = row.loginName;
      // this.editForm.password = row.password;
      // this.editForm.monitorIp = row.monitorIp;
      // this.editForm.xOriginal = row.xOriginal;
      // this.editForm.yOriginal = row.yOriginal;
    },
    isEdit() {
      this.$refs["editForm"].validate((valid) => {
        if (valid) {
          const formData = new FormData();
          for (const [key, value] of Object.entries(this.editForm)) {
            formData.append(key, value);
          }
          Axios({
            url: serviceApi.KB_API,
            method: "post",
            data: `appMsg={"parameter":"{\\"moduleEnum\\":\\"${this.editForm.moduleEnum}\\",\\"sensorName\\":\\"${this.editForm.sensorName}\\",\\"sensorId\\":\\"${this.editForm.sensorId}\\",\\"sensorNumber1\\":\\"${this.editForm.sensorNumber1}\\",\\"sensorNumber4\\":\\"${this.editForm.sensorNumber4}\\",\\"sensorNumber2\\":\\"${this.editForm.sensorNumber2}\\",\\"sensorNumber3\\":\\"${this.editForm.sensorNumber3}\\",\\"productEnum\\":\\"${this.editForm.productEnum}\\",\\"monitorPort\\":\\"${this.editForm.monitorPort}\\",\\"reportIntervalTime\\":\\"${this.editForm.reportIntervalTime}\\",\\"sensorModel\\":\\"${this.editForm.sensorModel}\\",\\"xOriginal\\":\\"${this.editForm.xOriginal}\\",\\"yOriginal\\":\\"${this.editForm.yOriginal}\\",\\"monitorIp\\":\\"${this.editForm.monitorIp}\\",\\"dataType\\":\\"${this.editForm.dataType}\\",\\"loginName\\":\\"${this.editForm.loginName}\\",\\"password\\":\\"${this.editForm.password}\\",\\"monitorId\\":\\"${this.editForm.monitorId}\\",\\"baseId\\":\\"${this.editForm.baseId}\\",\\"monitorProtocol\\":\\"${this.editForm.monitorProtocol}\\",\\"whetherAuthentication\\":\\"${this.editForm.whetherAuthentication}\\",\\"argumentG\\":\\"${this.editForm.argumentG}\\",\\"argumentL\\":\\"${this.editForm.argumentL}\\",\\"argumentK\\":\\"${this.editForm.argumentK}\\",\\"argumentT\\":\\"${this.editForm.argumentT}\\",\\"argumentR\\":\\"${this.editForm.argumentR}\\",\\"nozzleHeight\\":\\"${this.editForm.nozzleHeight}\\",\\"sensorSerialNumber\\":\\"${this.editForm.sensorSerialNumber}\\"}","serviceCode":"updateSensorInfo","timestamp":"","uuid":""}`,
          }).then((res) => {
            if (res.data.parameter.status == "0000") {
              this.editDevice = false;
              this.$message({
                message: "修改成功",
                type: "success",
                duration: 1000,
                onClose: () => {
                  let queryData = {
                    currentPage: "1",
                    sensorName: "",
                    moduleEnum: "",
                  };
                  this.deviceCollection(queryData);
                  this.$refs.editForm.resetFields();
                },
              });
            } else {
              this.$message({
                message: res.data.message,
                type: "warning",
              });
            }
          });
        } else {
          this.$message({
            type: "error",
            message: "请完善表单信息",
            offset: 400,
            duration: 1000,
          });
        }
        this.editDevice = false;
      });
    },
    closeEditDialog() {
      this.editDevice = false;
      this.$refs.editForm.resetFields();
    },
    del(row) {
      this.$confirm("您确定要删除该条数据吗？", "删除用户", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          Axios({
            url: serviceApi.KB_API,
            method: "post",
            data: `appMsg={"parameter":"{\\"sensorId\\":\\"${row.id}\\",\\"memberType\\":\\"${row.memberType}\\"}","serviceCode":"deleteSensorInfo","timestamp":"","uuid":""}`,
          }).then((res) => {
            let message = res.data.parameter.message;
            this.$message({
              type: "success",
              message: message,
              duration: 1000,
              onClose: () => {
                let queryData = {
                  currentPage: "1",
                  sensorName: "",
                  moduleEnum: "",
                };
                this.deviceCollection(queryData);
              },
            });
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消删除!",
          });
        });
    },
  },
};
</script>

<style lang="less" scoped>
.el-alert {
  line-height: 30px;
  margin-top: 20px;
  /deep/ .el-alert__title {
    font-size: 16px;
  }
}
.el-form {
  margin: 20px 0;
  margin-left: 30px;
}
.buttonfrom {
  margin-left: 250px;
  /* background: red; */
}
.el-input {
  width: 230px;
}
</style>